home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
bix02.arc
/
FIB.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-08-04
|
4KB
|
123 lines
(* Contributed to WelchNet 415-664-2811 by Neil Rubenking 2/21/86 *)
(**)
(* This program shows how to access the file information block. *)
(**)
(**)
program file_info;
(* ================================================================== *)
(* TURBO procedures can treat logical devices as if they were text *)
(* files. However, the programmer might want to do something just *)
(* a LITTLE different depending on which file or device comes to *)
(* the procedure. The File Interface Block corresponding to the *)
(* file or device contains quite a bit of information which can *)
(* be useful in such a case. This little program demonstrates *)
(* a procedure to make use of that information. *)
(* ================================================================== *)
(* NOTE that the FIB information here is DOS-specific. CP/M users *)
(* have similar information available, in a slightly different *)
(* format. *)
(* ================================================================== *)
type
Flag_Set = set of (b0,b1,b2,b3,b4,Char_Waiting,Out_Okay, In_Okay);
fancy_FIB = record {<-- see TURBO 3.0 manual, p. 220}
handle : integer;
F : record
case boolean of
true : (ftype : byte);
false : (flags : flag_set);
end;
chBuff : byte;
Buff_Offset,
Buff_Size,
Buff_Pointer,
Buff_End : integer;
path : array[0..63] of char;
end;
HexString = string[4];
var
TextFile : text;
TextFil2 : text[$123]; {<-- specifies a file buffer of $123 bytes }
TextFil3 : text;
FUNCTION Hex(II : Integer) : HexString;
CONST
HexDig : STRING[16] = '0123456789ABCDEF';
VAR
temp : HexString;
BEGIN
temp[0] := #4;
temp[1] := HexDig[((Hi(II) AND $FF) SHR 4)+1];
temp[2] := HexDig[((Hi(II) AND $FF) AND $F)+1];
temp[3] := HexDig[((Lo(II) AND $FF) SHR 4)+1];
temp[4] := HexDig[((Lo(II) AND $FF) AND $F)+1];
Hex := temp;
END;
procedure Do_File_Thing(VAR F );
var
FIB : Fancy_FIB absolute F;
N : byte;
begin
WriteLn('REPORT on a text file or device :');
with FIB do
begin
case F.ftype and $F of
0: begin
Write('A disk file: "');
N := 0;
while (N < 63) and (path[N] <> #0) DO
begin
write(path[N]);
N := N + 1;
end;
writeLn('"');
IF (Out_Okay in F.Flags) or (In_Okay in F.Flags) THEN
BEGIN
WriteLn('The handle is ',handle);
write('BUFFER starts at ',hex(Buff_Offset));
write(', ends at ',hex(buff_end));
write(', size is ',hex(buff_size));
writeLn(' and current pointer is ',hex(buff_pointer));
IF Char_Waiting in F.Flags THEN
writeLn('CHAR waiting is ',chBuff)
ELSE writeLn('NO char waiting');
END
ELSE
WriteLn('The file is not yet open.');
end;
1: writeLn('CON: device');
2: writeLn('KBD: device');
3: writeLn('LST: device');
4: writeLn('AUX: device');
5: writeLn('USR: device');
end;
IF Out_Okay in F.flags THEN writeLn('Open for output.');
IF IN_Okay in F.flags THEN writeLn('Open for input.');
end;
writeLn;
end;
begin
assign(TextFile,'FilDat.pas');
Do_File_Thing(TextFile);
reset(TextFile);
Do_File_Thing(TextFile);
assign(TextFil2,'FilDat.pas');
reset(TextFil2);
Do_File_Thing(TextFil2);
WriteLn('Press a key to continue . . .');
repeat until keypressed; read(Kbd);
assign(TextFil3,'SomeDumb.fil');
rewrite(TextFil3);
Do_File_Thing(TextFil3);
close(TextFile);
close(TextFil2);
close(TextFil3);
Do_File_Thing(Lst);
Do_File_Thing(Kbd);
Do_File_Thing(output);
end.